import { computed } from 'vue'
export const getStatusText = (status: number) => {
  if (status === 0) {
    return "未上架"
  } else if (status === 1) {
    return "已上架"
  }
}
export const getStatusColor = (status: number) => {
  if (status === 0) {
    return "error"
  } else if (status === 1) {
    return "success"
  }
}

export interface dropdownMenuType {
  title: string
  type: string
  showIcon?: boolean
  prop: string
  value?: string | number | null
  options?: Array<{
    label: string
    value: string | number | null
  }>
}
export const dropdownMenuList: dropdownMenuType[] = [
  {
    title: '搜索',
    type: 'search',
    prop: 'name',
  },
  {
    title: '分类',
    type: 'cell',
    showIcon: true,
    prop: 'categoryId',
    options: []
  },
  {
    title: '排序',
    type: 'cell',
    showIcon: true,
    prop: 'orderBy',
    options: [{
      label: '综合排序',
      value: null
    }, {
      label: '最新发布',
      value: 'create_time desc'
    }, {
      label: '低价优先',
      value: 'price asc'
    }, {
      label: '高价优先',
      value: 'price desc'
    }]
  }
]

export const goodsRules = {
  name: [
    {
      required: true,
      message: '请输入商品名称',
      trigger: 'blur'
    },
    {
      min: 1,
      max: 100,
      message: '长度在 1 到 100 个字符之间',
      trigger: 'blur'
    }
  ],
  price: [
    {
      required: true,
      message: '请输入商品价格',
      trigger: 'blur'
    },
    {
      min: 0,
      max: 10000,
      message: '价格范围在 0 到 100 之间',
    }
  ],
  description: [
    {
      required: true,
      message: '请输入商品描述',
      trigger: 'blur'
    }
  ]
}

export const imageStyle = computed(() => {
  const w = uni.upx2px(750) / 4
  const rate = w / 600
  const h = rate * 400
  return {
    width: w + 'px',
    height: h + 'px'
  }
})